<?php		
/*
**********************************************
JoomLeague EVENTS STATISTIC MODULE modified for basketball extension
Copyright (c) 2007 JoomLeague.de
**********************************************
This program is free software; you can redistribute it and/or modify 
it under the terms of the GNU General Public License as published by 
the Free Software Foundation; either version 2 of the License, or 
(at your option) any later version.

This header must not be removed. Additional contributions/changes
may be added to this header as long as no information is deleted.
**********************************************

* EVENTS STATISTIC MODULE
*
* 2008-01-08 - Version 0.92
*
* Displays a selected eventtype list (e.g. goals or yellow cards) for the 
* choosen project.
* There are some options for this module, which can be set in the 
* "Parameters" section of the module in Administration.
*

**********************************************
Get the latest version of JoomLeague at:
http://www.joomleague.de//
**********************************************
*/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

if (file_exists($mosConfig_absolute_path.'/components/com_joomleague/language/'.$mosConfig_lang.'.php')) {
  include_once($mosConfig_absolute_path.'/components/com_joomleague/language/'.$mosConfig_lang.'.php');
} 
else {
  include_once($mosConfig_absolute_path.'/components/com_joomleague/language/english.php');
}

require_once 'administrator/components/com_joomleague/joomleague.class.php';

$p         = intval($params->get( 'project', 0 ));
$show      = $params->get( 'show', 0 );
//$division  = intval($params->get( 'division', 0 ));
$eventtype = intval($params->get( 'eventtype', 0 ));
$limit     = intval($params->get( 'limit', 5 ));

$project = new JoomLeague( $database );
$project->load($p);

// get the model
require_once 'components/com_joomleague/frontend/'.$project->template.'/models/eventsstats.php';
$model = new BasketballModelEventsStats();


// get project parameter
global $overall_config;
$overall_config = $project->getTemplateConfig("overall.tpl");
//print_r($overall_config);

//get the ranking
$rows = $model->getEventsRanking($p, $eventtype, $limit, 0);
    
$player_ids = array();
foreach ( $rows as $r ) {
  $player_ids[] = $r->player_id;
}
$players = $model->getPlayersInfo( $player_ids );

if($show == 1) {
  ?><div align="center"><b><?php echo $project->name;?></b></div><?php 
}
  
?>
    
<table width="100%" align="center" border="0" cellpadding="2" cellspacing="0">
  <?php
  $k = 0;
  $rank = 1;
  foreach($rows as $row)
  {
    $ptid = $row->player_id;
    $class = ($k == 0)? 'sectiontableentry1' : 'sectiontableentry2';
    ?>
    <tr class="<?php print $class;?>">
      <td><?php echo $rank++;?></td>
      <td align="left"><?php echo sprintf("%s %s (%s)",$players[$ptid]->firstname, $players[$ptid]->lastname, $players[$ptid]->team_short);?></td>
      <td align="right"><?php echo $row->p;?></td>
    </tr>
    <?php     
    $k = 1 - $k;
  }
  ?>
</table>
